﻿using Mapster;
using Zhp.Entity.Formula;
using Zhp.IService.Formula;
using Zhp.IService.Formula.VariableClass;
using Zhp.Service.Base;
using Zhp.SqlSugar.Repository;

namespace Zhp.Service.Formula
{
    public class FormulaTestService : BaseService<FormulaTest>, IFormulaTestService
    {
        private readonly IFormulaCalcService _formulaCalcService;
        public FormulaTestService(IBaseRepository<FormulaTest> rep, IFormulaCalcService formulaCalcService)
        {
            _rep = rep;
            _formulaCalcService = formulaCalcService;
        }
        public async Task<bool> Calc(long id)
        {
            var test = await _rep.GetByIdAsync(id);

            var data = test.Adapt<FormulaVariableTest>();
            var formulaValue = await _formulaCalcService.Calc(data);

            test.FormulaValue = formulaValue;
            return await _rep.UpdateAsync(test);
        }
    }
}
